package com.situ.mall.service.impl;

import com.situ.imall.util.JSONResult;
import com.situ.mall.mapper.UserMapper;
import com.situ.mall.pojo.User;
import com.situ.mall.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author 周轩霆
 * @Date 2022/8/26 12:00
 **/
@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public JSONResult login(Map params, HttpSession session) {
        User user = userMapper.getUserByUsernameAndPassword(params);
        if (user == null) {
            return JSONResult.error("用户名或密码错误");

        } else {
            //保存到session域做登录验证
            session.setAttribute("user", user);
            return JSONResult.ok("登录成功!");
        }

    }
}
